package wkt.question;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class Question {
    private Long id;
    private String basicCode;
    private String type;// DANXUAN/DUOXUAN/TIANKONG/MINGCIJIESHI/LUNSHU
    private String question;
    private String analyzes;
    private String state;
    private LocalDateTime createTime;

    @TableField(exist = false)
    private boolean stared;

    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private boolean clearPreviousAnswerProcess;
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private boolean fromWrongBook;
    @TableField(exist = false)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private Long seqId;

    @TableField(exist = false)
    private List<Answer> answers;
    @TableField(exist = false)
    private long myRightAnswerCount;
    @TableField(exist = false)
    private long myWrongAnswerCount;

    public long getMyTotalAnswerCount() {
        return myRightAnswerCount + myWrongAnswerCount;
    }

    public Double getMyRightPercent() {
        if (getMyTotalAnswerCount() == 0) return null;
        return (double) Math.round((float) myRightAnswerCount / getMyTotalAnswerCount() * 10000) / 100.0;
    }

}
